/**@file
 * @brief solution.h实现
 * @author 朱项男<libxiangnan@gmail.com>
 * @date 2011/11/24
 * @version 0.0.1
 *
 * */

#include <string>
#include <vector>
#include <assert.h>

#include "solution.h"
#include "suite.h"

using namespace std;

namespace dat {
//! @brief 构造函数
Solution::Solution() :
		solutions(std::vector<Solution>()), suites(std::vector<Suite>()){
	;
}

//! @brief 析构函数
Solution::~Solution() {
	;
}

//! @brief 添加下一级Solution
//! @param[in] solution 下一级Solution
void Solution::add(const Solution &solution) {
	solutions.push_back(solution);
}

//! @brief 添加下一级Suite
//! @param[in] suite 下一级Suite
void Solution::add(const Suite &suite) {
	suites.push_back(suite);
}

//! @brief solutions Setter
//! @param[in] solutions 下一级solution
void Solution::setSolutions(const std::vector<Solution> &solutions) {
	this->solutions = solutions;
}

//! @brief solutions Getter
//! @return 下一级Solutions
std::vector<Solution> Solution::getSolutions() {
	return solutions;
}

//! @brief suites Setter
//! @param[in] suites 下一级Suites
void Solution::setSuites(const std::vector<Suite> &suites) {
	this->suites = suites;
}

//! @brief suites Getter
//! @return 子Suits
std::vector<Suite> Solution::getSuits() {
	return suites;
}

//! @brief 根据ID移除下一级Solution/Suit
//! @param id Solution/Suit ID
//! @return 如果成功移除返回true；否则返回false
bool Solution::rmById(const std::string &id) {
	for(std::vector<Solution>::iterator iter = solutions.begin(); iter != solutions.end(); ++iter) {
		if(0 == id.compare((*iter).getId())) {
			solutions.erase(iter);
			return true;
		}
	}
	for(std::vector<Suite>::iterator iter = suites.begin(); iter != suites.end(); ++iter) {
		if(0 == id.compare((*iter).getId())) {
			suites.erase(iter);
			return true;
		}
	}
	return false;
}

//! @brief 清空下一级Solutions
void Solution::emptySolutions() {
	if(!solutions.empty()) {
		solutions.clear();
	}
}

//! @brief 清空下一级Suites
void Solution::emptySuites() {
	if(!suites.empty()) {
		suites.clear();
	}
}

//! @brief 清空全部下一级
void Solution::emptyAll() {
	emptySolutions();
	emptySuites();
}

} /* namespace dat */
